import 'package:flutter/material.dart';

import '../../../../databases/booklist.dart';
import '../../../../widgets/common_image.dart';

class BookListWidget extends StatefulWidget {
  BookListWidget({Key? key}) : super(key: key);

  @override
  State<BookListWidget> createState() => _BookListWidgetState();
}

class _BookListWidgetState extends State<BookListWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(bottom: 70.0),
      padding: EdgeInsets.all(8.0),
      width: MediaQuery.of(context).size.width,
      child: ListView.builder(
        itemBuilder: (BuildContext context, int index) {
          return Container(
            width: MediaQuery.of(context).size.width,
            padding: EdgeInsets.all(8.0),
            decoration: BoxDecoration(
                border:
                    Border(bottom: BorderSide(width: 1.0, color: Colors.grey))),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      bookListData[index].title!,
                      style: TextStyle(
                          fontSize: 18.0, fontWeight: FontWeight.w400),
                    ),
                    Text(
                      bookListData[index].subTitle!,
                      style: TextStyle(
                          fontSize: 16.0, color: Colors.grey.shade400),
                    ),
                    Padding(
                      padding: EdgeInsets.only(top: 28.0),
                      child: Text("共${bookListData[index].num!}本书"),
                    ),
                  ],
                ),
                Container(
                    width: 100.0,
                    height: 100.0,
                    child: CommonImage(bookListData[index].bookListImgUrl!))
              ],
            ),
          );
        },
        itemCount: bookListData.length,
      ),
    );
  }
}
